package ComDirectBehaviour;

import java.io.IOException;
import java.util.ArrayList;

import Message.MEnnemie;
import Message.MState;
import Message.ReqReparation;
import jade.core.AID;
import jade.core.behaviours.Behaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.UnreadableException;
import Goal.GoalBase;
import Perception.PerceptsBase;
import Perception.Percepts;
import Message.MNoeud;
import Message.MEnnemie;
import Message.MReparationOK;

import java.util.HashSet;
/**
 * TODO description
 */
public class ComInfoRep extends Behaviour {
	
	public void checkMessage(ACLMessage msg)
	{
		original(msg);
		checkInfo(msg);
	}

	
	public void checkInfo(ACLMessage msg) 
	{
			try{
				String id =msg.getConversationId(); 
				if(id.equals("Req-Ok"))
				{
					ReqReparation req = (ReqReparation)msg.getContentObject();
					HashSet<String> liste = ((HashSet<String>)goals.getAllGoals().clone());
					for(String goal : liste)
					{
						if(goal.contains("Rep-"+req.getName()))
							goals.removeGoal(goal);
							
					}
					
				}
				else if(id.equals("Rep-R"))
				{
					ReqReparation req = (ReqReparation)msg.getContentObject();
					HashSet<String> liste = (HashSet<String>)(goals.getAllGoals().clone());
					for(String goal : liste)
					{
						if(goal.contains("Rep-"+req.getName()))
							goals.removeGoal(goal);
					}
					goals.addGoal("Rep-"+req.getName()+"-"+req.getPosition());
				}
			}
			catch(UnreadableException e)
			{
				System.err.println(e.getMessage());
			}
	}
	
}